/* 
 * File:   DynamicArray.h
 * Author: mori
 *
 * Created on May 1, 2011, 2:49 AM
 */
#include <matrix.h>





#ifndef _DYNAMICARRAY_H
#define	_DYNAMICARRAY_H

template <typename T>
T **AllocateDynamicArray(int nRows, int nCols) {
    T **dynamicArray;

    dynamicArray = new T*[nRows];
    for (int i = 0; i < nRows; i++)
        dynamicArray[i] = new T [nCols];

    return dynamicArray;
};

template <typename T>
void CopyDynamicArray(T** srcArray, T** dstnArray, int nRows, int nCols) {
    for (int j = 0; j < nCols; j++) {
        for (int i = 0; i < nRows; i++) {

            dstnArray[i][j] = srcArray[i][j];

        }
    }
    
};

template <typename T>
void ReadDynamicArray(const char* file_name, T** srcArray, int nRows, int nCols) {
    FILE* f = fopen(file_name, "rt");
    float r,z = 0;
    for (int j = 0; j < nCols; j++) {
        for (int i = 0; i < nRows; i++) {

        //  srcArray[i][j];
          fscanf(f, "%f %f %f", &r, &z, &srcArray[i][j]);

        }
    }
    fclose(f);
};



template <typename T>
void FreeDynamicArray(T** dArray) {
    delete [] * dArray;
    delete [] dArray;
}

#endif	/* _DYNAMICARRAY_H */

